
/**
 * Module dependencies.
 */

var routes = require('./routes');
var httpserver = require('./httpserver.js');
var app = httpserver.app;
/**
 * 路由配置
 */
app.get('/', routes.login);
app.get('/reg',routes.reg);
app.post('/reg',routes.doReg);
app.all('/login', notAuthentication);
app.get('/login', routes.login);
app.post('/login', routes.doLogin);
app.get('/logout', authentication);
app.get('/logout', routes.logout);

app.post('/upload',routes.upload);
app.post('/send',routes.send);
app.post('/remove',routes.remove);
app.post('/cfginfo',routes.cfginfo);
app.post('/cfg',routes.cfg);
app.post('/kindeditor/upload',routes.kindeditor);

app.get('/test',function(req,res){
    res.render('test',{ title: 'test'});
});
function authentication(req, res, next) {
if (!req.session.user) {
req.session.error='请先登陆';
return res.redirect('/login');
}
next();
}
function notAuthentication(req, res, next) {
if (req.session.user) {
req.session.error='已登陆';
return res.render('home',{title:'个人中心',user:req.session.user});
}
next();
}